package com.jic.product;

import com.github.pagehelper.PageHelper;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import com.jic.common.swagger.config.Swagger2Config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.PostConstruct;
import java.util.Properties;
import java.util.TimeZone;

/**
 * @author: gaoly
 * @date: 2019/11/21
 * @remark:
 */
@SpringBootApplication
@EnableFeignClients(basePackages = {"com.jic.manager.api", "com.jic.conf.api", "com.jic.member.api", "com.jic.market.api","com.jic.order.api"})
@EnableSwagger2
@MapperScan("com.jic.product.mapper")
@EnableSwaggerBootstrapUI
@EnableTransactionManagement
@EnableDiscoveryClient
public class JicProductApplication {
    public static void main(String[] args) {
        SpringApplication.run(JicProductApplication.class, args);
    }

    @Bean
    @ConditionalOnMissingBean
    public Docket getDocket() {
        return new Swagger2Config().createRestApi(this.getClass().getSimpleName());
    }

    //配置mybatis的分页插件pageHelper
    @Bean
    public PageHelper pageHelper() {
        PageHelper pageHelper = new PageHelper();
        Properties properties = new Properties();
        properties.setProperty("offsetAsPageNum", "true");
        properties.setProperty("rowBoundsWithCount", "true");
        properties.setProperty("reasonable", "true");
        properties.setProperty("dialect", "mysql");    //配置mysql数据库的方言
        pageHelper.setProperties(properties);
        return pageHelper;
    }

    /**
     * 时区设置
     */
    @PostConstruct
    void started() {
        TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
    }
}
